import 'dart:io';

import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/foundation.dart';
import 'package:package_info_plus/package_info_plus.dart';

import 'string_util.dart';

///组合头部请求的加密信息地方

class ApiHeadersGenerator {
  Future<Map<String, dynamic>> commonHeader() async {
    final info = await PackageInfo.fromPlatform();
    final deviceInfoPlugin = DeviceInfoPlugin();
    final header = <String, dynamic>{};
    String? identifier;

    if (!kIsWeb) {
      if (Platform.isAndroid) {
        final build = await deviceInfoPlugin.androidInfo;
        identifier = build.id;
        //UUID for Android
        header['platform'] = 'android';
      } else if (Platform.isIOS) {
        final data = await deviceInfoPlugin.iosInfo;
        identifier = data.identifierForVendor;
        header['platform'] = 'ios';
      }
      header['identifier'] = identifier;
    } else {
      header['platform'] = 'web';
    }

    header['token'] = '';
    header['version'] = info.version;
    header['noncestr'] = generateRandomString(16);
    header['timestamp'] = DateTime.now().millisecondsSinceEpoch;

    return header;
  }
}
